package v1

import (
	"context"

	authzv1 "gitee.com/youkelike/ziam/zapi/authz/v1"
	metav1 "gitee.com/youkelike/ziam/zapi/meta/v1"
	"gitee.com/youkelike/ziam/zsdk2/rest"

	"github.com/ory/ladon"
)

// type AuthzGetter interface {
// 	Authz() AuthzInterface
// }

type AuthzInterface interface {
	Authorize(ctx context.Context, request *ladon.Request, opts metav1.AuthorizeOptions) (*authzv1.Response, error)
	AuthzExpansion
}

type authz struct {
	client rest.Interface
}

func newAuthz(c *AuthzV1Client) *authz {
	return &authz{
		client: c.RESTClient(),
	}
}

func (c *authz) Authorize(ctx context.Context, request *ladon.Request,
	opts metav1.AuthorizeOptions) (result *authzv1.Response, err error) {
	result = &authzv1.Response{}
	err = c.client.Post().
		Resource("authz").
		VersionedParams(opts).
		Body(request).
		Do(ctx).
		Into(result)

	return
}
